<template>
  <div class="app-container">
    <div class="wise-crud">
      <div class="table-show">
        <div class="operation-block">
          <el-row class="oper-btn" :gutter="10">
            <el-col :span="16">
              <el-button type="primary" @click="handleAdd()"><i class="el-icon-plus" />添加</el-button>
            </el-col>
          </el-row>
        </div>
        <!--table-->
        <el-table :key="symbolKey" :data="tableData" border highlight-current-row row-key="id" lazy :load="load"
          :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
          <el-table-column label="序号" type="index" width="100" />
          <el-table-column label="名称" prop="name" />
          <el-table-column label="状态">
            <template slot-scope="scope">
              {{scope.row.confirmStatus==0?'未确认':'已确认'}}
            </template>
          </el-table-column>
          <el-table-column :label="$t('table.actions')" align="center" width="250">
            <template slot-scope="scope">
              <el-button v-if="scope.row.level === 10" size="mini" round type="info" @click="handleView(scope.row)">
                {{  $t("table.see") }}</el-button>
              <el-button v-if="scope.row.level === 10 && scope.row.confirmStatus != 1" round size="mini" type="success"
                @click="handleEdit(scope.row)">
                {{ $t("table.edit") }}</el-button>
              <el-button v-if="scope.row.level === 10 && scope.row.confirmStatus != 1" round size="mini" type="danger"
                @click="handleDelete(scope.row)">
                {{ $t("table.delete") }}</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="page-block">
          <pagination :background="true" layout="total,prev, pager, next" :total="ts" :page.sync="page.p"
            :limit.sync="page.ps" @pagination="getTableData" />
        </div>
      </div>
      <el-dialog ref="drawer" :title="title" :visible.sync="drawer" append-to-body destroy-on-close>
        <div v-if="drawer" class="draw-body">
          <word :loading="loading" @hideDijon='hideDijon' :object="object"></word>
          <!-- <wise-form :columns="formItems" :loading="loading" :old-object="object" @on-submit="submitHandle" /> -->
        </div>
      </el-dialog>
      <el-dialog ref="viewDrawer" title="查看" :visible.sync="viewDrawer" append-to-body close-on-press-escape
        destroy-on-close>
        <div class="draw-body">
          <!-- <wise-view :columns="viewItems" :object="object" /> -->
          <view-word v-if="viewDrawer" :id="id" :object='object' @hideDjog='hideDjog'></view-word>
        </div>
      </el-dialog>
      <el-dialog ref="editDrawer" title="编辑" width="60%" :visible.sync="editDrawer" @close="modelClose" append-to-body
        close-on-press-escape destroy-on-close>
        <div class="draw-body">
          <edit-word :id="id" v-if="editDrawer" @hideDjog1='hideDjog1'></edit-word>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
  import checkPermission from '@/pages/index/utils/permission'
  import WiseForm from '@/components/Crud/Form/wiseForm'
  // import WiseView from '@/components/Crud/View/wiseView'
  import ViewWord from './viewWord'
  import Pagination from '@/components/Pagination/index'
  import Word from '@/pages/enterprise/views/hotworkplan/word'
  import EditWord from '@/pages/enterprise/views/hotworkplan/editWord'
  import {
    postHandle
  } from '@/api'
  export default {
    name: 'PositionManage',
    components: {
      Pagination,
      ViewWord,
      WiseForm,
      Word,
      EditWord
    },
    data() {
      return {
        urls: {
          list: '/api/v1/welder-sbtx-second/hot-program-comb/list',
          add: '/api/v1/welder-uac-second/base-profession-comb/create-profession',
          show: '/api/v1/welder-sbtx-second/hot-program-comb/show/',
          update: '/api/v1/welder-sbtx-second/hot-program-comb/update/',
          delete: '/api/v1/welder-sbtx-second/hot-program-comb/remove/'
        },
        symbolKey: '',
        object: {},
        loading: false,
        tableData: [],
        formItems: [],
        viewItems: [],
        drawer: false,
        title: '',
        viewDrawer: false,
        editDrawer: false,
        ts: 0,
        id: '',
        page: {
          p: 1,
          ps: 20
        },
        object1: ''
      }
    },
    computed: {
      handle() {
        return ['add']
      },
      fields() {
        arr.push({
          label: '状态',
          prop: 'status',
          labelWidth: '190px',
          type: 'render',
          viewRender: (h, item, object) => {
            let divHtml = ""
            return h('div', divHtml)
          },
          use: ['view', 'table']
        })
        return arr
      }
    },
    mounted() {
      this.getTableData()
    },
    methods: {
      checkPermission,
      hideDijon(val) {

        this.drawer = val
        this.getTableData()
      },
      hideDjog(val) {
        this.viewDrawer = val
        this.getTableData()
      },
      hideDjog1(val) {
        this.editDrawer = val
        this.getTableData()
      },
      handleAdd() {
        this.title = '新增'
        this.drawer = true
        this.object = {}
      },
      handleEdit(row) {
        this.id = row.id
        this.editDrawer = true
      },
      handleView(row) {
        this.id = row.id
        this.object = row
        this.viewDrawer = true
      },
      modelClose() {
        this.editDrawer = false
        this.getTableData()
      },
      handleDelete(row) {
        this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
          .then(() => {
            this.deleteObjectById(row.id)
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            })
          })
      },
      submitHandle(obj) {
        this.loading = true
        let url = this.urls.add
        if (obj.id) {
          url = this.urls.update + obj.id
        }
        postHandle(url, {
            obj
          })
          .then((response) => {
            this.$message('操作成功')
            this.loading = false
            this.drawer = false
            this.page.p = 1
            this.getTableData()
          })
          .catch((error) => {
            this.loading = false
            this.$message.error('操作失败')
          })
      },
      getObjectById(id) {
        postHandle(this.urls.show + id, {}).then((response) => {
          this.object = response.result
        })
      },
      deleteObjectById(id) {
        postHandle(this.urls.delete + id, {})
          .then((response) => {
            this.getTableData()
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
          })
          .catch((error) => {
            this.$message.error('操作失败')
          })
      },
      getTableData() {
        const req = {
          d: {
            filters: [{
              field: 'entSpaceId',
              operator: 'EQUALS',
              value: this.$store.getters.entSpaceId
            }],
            page: this.page,
            retPage: true
          }
        }
        postHandle(this.urls.list, req).then((response) => {
          const data = response.result
          this.tableData = data
          this.ts = response.page.ts
          this.symbolKey = Symbol(new Date().toString())
        })
      },
      load(tree, treeNode, resolve) {
        
        const req = {
          d: {
            filters: [{
              field: 'pid',
              operator: 'EQUALS',
              value: tree.id
            }],
            page: {
              p: 1,
              ps: 9999
            }
          }
        }
        postHandle(this.urls.list, req).then((response) => {
          const data = response.result
          resolve(data)
        })
      }
    }
  }
</script>

<style scoped>
</style>